/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package onlinestore;
import java.sql.*;
/**
 *
 * @author Li
 */
public class Product {
    private int productID;
    private String name;
    private double price;
    private String brand;
    private int barcode;
    private String pic;

    private String searchitem;


    public String finProduct(String s)
    {
        try {
            //LOAD THE DRIVER
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            //CREATE URL STRING
            String URL = "jdbc:mysql://127.0.0.1:3306/onlinestore?user=root&password=1989";
            //CONNECTING TO SQL
            Connection c = DriverManager.getConnection(URL);
            //CONNECTED
            Statement st = c.createStatement();
            //COMMAND
            ResultSet rs = st.executeQuery("SELECT * FROM `onlinestore`.`product` Where name = '"+s+"'");
            while(rs.next()){
                setBrand(rs.getString("brand"));
                setPic(rs.getString("pic"));
                setName(rs.getString("name"));
                setPrice(rs.getDouble("price"));
                System.out.println(getName()+"/"+getBrand()+"/"+getPic());
            }

            System.out.println("YOU SEARCH FOR :["+getName()+"]");
            c.close();

        } catch (Exception e) {
            System.err.println("ERROR: " + e);
        }
        return getName();
    }

    public String showProduct(String s)
    {
        try {
            //LOAD THE DRIVER
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            //CREATE URL STRING
            String URL = "jdbc:mysql://127.0.0.1:3306/onlinestore?user=root&password=1989";
            //CONNECTING TO SQL
            Connection c = DriverManager.getConnection(URL);
            //CONNECTED
            Statement st = c.createStatement();
            //COMMAND
            ResultSet rs = st.executeQuery("SELECT * FROM `onlinestore`.`product` Where name = '"+s+"'");
            while(rs.next()){
                setBrand(rs.getString("brand"));
                setPic(rs.getString("pic"));
                setName(rs.getString("name"));
                setPrice(rs.getDouble("price"));

                System.out.println(getName()+"/"+getBrand()+"/"+getPic());
            }

            System.out.println("YOU SEARCH FOR :["+getName()+"]");
            c.close();

        } catch (Exception e) {
            System.err.println("ERROR: " + e);
        }
        return getName();
    }
   

    /**
     * @return the productID
     */
    public int getProductID() {
        return productID;
    }

    /**
     * @param productID the productID to set
     */
    public void setProductID(int productID) {
        this.productID = productID;
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the price
     */
    public double getPrice() {
        return price;
    }

    /**
     * @param price the price to set
     */
    public void setPrice(double price) {
        this.price = price;
    }

    /**
     * @return the brand
     */
    public String getBrand() {
        return brand;
    }

    /**
     * @param brand the brand to set
     */
    public void setBrand(String brand) {
        this.brand = brand;
    }

    /**
     * @return the barcode
     */
    public int getBarcode() {
        return barcode;
    }

    /**
     * @param barcode the barcode to set
     */
    public void setBarcode(int barcode) {
        this.barcode = barcode;
    }

    /**
     * @return the pic
     */
    public String getPic() {
        return pic;
    }

    /**
     * @param pic the pic to set
     */
    public void setPic(String pic) {
        this.pic = pic;
    }

    /**
     * @return the searchitem
     */
    public String getSearchitem() {
        return searchitem;
    }

    /**
     * @param searchitem the searchitem to set
     */
    public void setSearchitem(String searchitem) {
        this.searchitem = searchitem;
    }
}
